package com.wanxi.servlet;

import com.wanxi.model.ImageShowModel;
import com.wanxi.model.NavModel;
import com.wanxi.model.NewsModel;
import com.wanxi.service.AboutService;
import com.wanxi.service.NewsService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;

@WebServlet("/news")
public class NewsServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//        乱码处理
        req.setCharacterEncoding(StandardCharsets.UTF_8.toString());
        resp.setCharacterEncoding(StandardCharsets.UTF_8.toString());
//        数据给服务端处理
        NewsService newsService=new NewsService();
        List<NavModel> navModelList=new ArrayList<>();
        List<NewsModel> newsModelList=new ArrayList<>();
        List<NavModel> newsNavModelList=new ArrayList<>();

        navModelList=newsService.getNavModelList();
        newsNavModelList=newsService.getNewsNavModelList();
        newsModelList=newsService.getNewsList();
//        数据存储
        req.setAttribute("navModelList",navModelList);
        req.setAttribute("newsModelList",newsModelList);
        req.setAttribute("newsNavModelList",newsNavModelList);

//        页面转发
        req.getRequestDispatcher("page/news.jsp").forward(req,resp);
    }
}
